<?php

// Doctrine autoloader needs to be loaded for this class

include_once 'CF_ProcessorBase.php';

class CF_ProcessorBaseTest extends CF_ProcessorBase {

	var $ModelName;

	function CalculateModelName(){
		$this->ModelName = $Doctrine_Inflector::classify($this->maintable);
		
	}

	
	function set_maintable($thetablename){
		$this->maintable = $thetablename;
		$this->CalculateModelName();
	}		

	
	function SaveMultiple(){
		if(is_array($this->keyvalues)){
		foreach($this->keyvalues AS $keyindex => $keys){
			$q = Doctrine_Query::create()
			$q->from($this->ModelName);
				$ar_values = array();
				$firstwhere = true;
				foreach($keys AS $col_name => $col_value){
					if($firstwhere){
						$q->where($this->ModelName . '.' . $col_name . ' = ?');
					}else{
						$q->andWhere($this->ModelName . '.' . $col_name . ' = ?');		
					}
					$ar_values[]= $col_value;
				} // end foreach key	
			$instance = $q->fetchOne($ar_values);
			foreach($this->newvalues[$keyindex] AS $col => $value){
				$instance[$col] = $value;		
			}
			$instance->save();
		}
		}

	
	}
	
	function DeleteMultiple(){
		if(is_array($this->keyvalues)){
		foreach($this->keyvalues AS $keyindex => $keys){
			$q = Doctrine_Query::create()
			$q->from($this->ModelName);
				$ar_values = array();
				$firstwhere = true;
				foreach($keys AS $col_name => $col_value){
					if($firstwhere){
						$q->where($this->ModelName . '.' . $col_name . ' = ?');
					}else{
						$q->andWhere($this->ModelName . '.' . $col_name . ' = ?');		
					}
					$ar_values[]= $col_value;
				} // end foreach key	
			$instance = $q->fetchOne($ar_values);
			$instance->delete();
		}}
	}
	
	function AddMultiple(){
	
		if(is_array($this->newvalues)){
			$instance = new $this->ModelName;		
			foreach($this->newvalues AS $column => $value){
				$instance[$column] = $value;
			}
			$instance->save();
		}

		
	}
	
	
}

?>